<%@ page language="java" pageEncoding="ISO-8859-1"%>
<%@page import="java.util.Iterator"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
<%@ taglib uri="http://struts.apache.org/tags-nested" prefix="nested" %>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <html:base />
    
    <title>Textbook Crossroads - Book Details</title>

	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<link rel="stylesheet" href="<%=request.getContextPath() %>/default.css" type="text/css">

  </head>
  
  <body>
  
  <div id="header">
	<div id="logo">
		<h1>
			<html:img width="40" src="../images/EMPTY.GIF"/>
			<html:link page="/pages/home.jsp">Textbook Crossroads</html:link>
		</h1>
		<h2>Team 14 - LoneTree</h2>
	</div>
	<div id="menu">
		<ul>
			<li>
			<logic:notPresent name="logged_in_user_in_session">
			<html:link page="/pages/home.jsp">Home</html:link>
			</logic:notPresent>
			<logic:present name="logged_in_user_in_session">
			<logic:equal value="false" name="logged_in_user_in_session" property="admin">
			<html:link action="/PrepForMyBooks">Dashboard</html:link>
			</logic:equal>
			<logic:equal value="true" name="logged_in_user_in_session" property="admin">
			<html:link page="/pages/admindashboard.jsp">Dashboard</html:link>
			</logic:equal>
			</logic:present>
			</li>
			<li class="active"><html:link page="/pages/books.jsp">Books</html:link></li>
			<li><html:link page="/pages/courses.jsp">Courses</html:link></li>
			<li><html:link page="/pages/about.jsp">About</html:link></li>
			<li class="logon">
			<logic:notPresent name="logged_in_user_in_session">
			<html:link page="/pages/logon.jsp">LogIn</html:link>
			</logic:notPresent>
			<logic:present name="logged_in_user_in_session">
			<html:link action="/logout">LogOut</html:link>
			</logic:present>
			</li>
		</ul>
	</div>
</div>
  
  <logic:notPresent name="book">
  <h1>No Book Selected</h1>
  </logic:notPresent>

<div id="content">
	<div id="sidebar">
		<div id="categories">
			<div id="archives" class="boxed">
				<logic:notPresent name="logged_in_user_in_session">
						<h2>Contributors</h2>
				</logic:notPresent>
			
				<logic:present name="logged_in_user_in_session">			
					<logic:equal value="true" name="logged_in_user_in_session" property="admin">						
						<h2>Admin Actions</h2>										
					</logic:equal>
				
					<logic:equal value="false" name="logged_in_user_in_session" property="admin">
						<h2>MyActions</h2>						
					</logic:equal>
				</logic:present>
				
				<div class="content">
					<logic:notPresent name="logged_in_user_in_session">
						<ul>
							<li>Andrew Lee</li>
							<li>Bojan Martin</li>
							<li>Dimeji Omikunle</li>
							<li>Minghui Yu</li>
						</ul>
					</logic:notPresent>
					
					<logic:present name="logged_in_user_in_session">
						<ul>
							<logic:equal value="false" name="logged_in_user_in_session" property="admin">
					    		<li><html:link page="/PrepForMyBooks.do?manage=books">Manage MyBooks</html:link></li>
					            <li><html:link page="/PrepForMyBooks.do?manage=sections">Manage MySections</html:link></li>
					            <li><html:link action="/UpdateMyProfile">Update MyProfile</html:link></li>
							</logic:equal>
							
							<logic:equal value="true" name="logged_in_user_in_session" property="admin">
					    		<li><html:link href="bookadmin.jsp"><bean:message
					            key="adminbook.link"/></html:link></li>
					            
					            <li><html:link action="/AdminCourses"><bean:message
					            key="admincourses.link"/></html:link></li>
					            
					            <li><html:link action="/AdminAccounts"><bean:message
					            key="adminaccounts.link"/></html:link></li>
					            
					            <li><html:link action="/AdminComments"><bean:message
					            key="admincomments.link"/></html:link></li>
							</logic:equal>
						</ul>	
					</logic:present>
				</div>
			</div>
		</div>
	</div>

	<div id="posts">
		<div class="post">
			<h2 class="title">Book Details</h2>
			<div class="meta">
				<p class="date">Book Info:</p>
			</div>
			<div class="story">
  <logic:present name="book">
      <h3>Book ISBN:</h3>
   <bean:write name="book" property="isbn" />
   <br>
   
  <logic:present name="AmazonBook">
  
  <table>
  <tr>
  <td>
  <a href=" <bean:write name=AmazonBook" property="largeImageURL" />">
  <bean:write name="AmazonBook" property="smallImageURL" /></a>
  <center>  <bean:write name="AmazonBook" property="price" /></center>
  </td>
  </tr>
  <tr>
  <td>
  <center>   <bean:write name="AmazonBook" property="title" />
  <a href=" <bean:write name=AmazonBook" property="bookUrl" />">
 Buy from Amazon now!</a>
 <bean:write name="AmazonBook" property="title" /></center>
  </td>
  </tr>
  </table>
  </logic:present>
   
  <h3>Book Title:</h3>
  <bean:write name="book" property="title" />
  <h3>Author(s):</h3>
  <bean:define id="test" name="book" type="org.lonetree.tc.core.Book" />
  <% 
  Iterator<String> itr=test.getAuthors().iterator();
  while (itr.hasNext())
  {
	  out.println(itr.next());
	  out.println("<br>");
  }
	  %>

<html:link page="/UpdateBook.do" paramName="book" paramProperty="isbn" paramId="isbn">Edit Book</html:link>
  </logic:present>
  <br/><br/>
  <html:link page="/ViewBookSections.do" paramName="book" paramProperty="isbn" paramId="isbn">
  View Book Section Details
  </html:link><br/>
  
  <logic:present name="sections">
<nested:iterate id="record" name="sections" >
<nested:text property="professor"></nested:text>
</nested:iterate>
    <logic:iterate name="sections" id="section">
    <bean:write name="section" property="parentCourse.title" />
    </logic:iterate>
   
  <logic:notEmpty name="sections">
  <h3>This book is used in the following section(s):</h3>
  <logic:iterate name="sections" id="section">
  <h4>Courses:</h4>
  <html:link page="/ViewCourseDetails.do" paramName="section" paramProperty="section.parentCourse.courseId" paramId="course_id">
  <bean:write name="section" property="parentCourse.title" /><br/>
  </html:link>
   <h4>Section:</h4>
  <html:link page="/ViewSectionDetails.do" paramName="section" paramProperty="sectionId" paramId="section_id">
  <bean:write name="section" property="sectionId.sectionIdString" /><br/>
  </html:link>
  <h4>Professor:</h4>
  <bean:write name="section" property="professor" /><br/>
  </logic:iterate>  
  </logic:notEmpty>
  </logic:present>
  
 <logic:notPresent name="sections">
  <h3>This book is not used in any sections</h3>
  </logic:notPresent>
  
  <logic:present name="comments">
   <logic:notEmpty name="comments">
  <h3>This book has received the following comments:</h3>
  <logic:iterate name="comments" id="comment">
  <html:link page="/UpdateBookComment.do" paramName="comment" paramProperty="bookCommentId" paramId="comment_id">
    <bean:write name="comment" property="comment" /></html:link>&nbsp;&nbsp;&nbsp;
     <html:link page="/DeleteBookComment.do" paramName="comment" paramProperty="bookCommentId" paramId="comment_id">
   Delete</html:link> 
   
      <a href="../UpdateBookComment.do?comment_id=<bean:write name="comment" property="bookCommentId" />&isbn=<bean:write name="book" property="isbn" />">Edit</a>
    <br/>
  </logic:iterate>  
 </logic:notEmpty>
  </logic:present>
  
  
  <logic:notPresent name="comments">
  <h3>There are no comments for this book</h3>
  </logic:notPresent>  
  
  <%
  	if (request.getParameter("isbn")!=null)
  	{
  		out.println("<a href='../AddBookComment.do?isbn="+request.getParameter("isbn")+"'>Add a comment</a>");
  	}
  %>
 
  
  <logic:present name="sources">
  <logic:notEmpty name="sources">
  <h3>This book is available from the following sources:</h3>
  <table width="100%" cellspacing="0" cellpadding="5">
	  <tr>
		  <th>Name</th>
		  <th>Description</th>
		  <th>Price</th>
		  <th>&nbsp;</th>
	  </tr>
	  <logic:iterate name="sources" id="source">
		  <tr>
			  <td><bean:write name="source" property="name" /></td>
			  <td><bean:write name="source" property="description" /></td>
			  <td>f=<bean:write name="source" property="price" /></td>
			  <td>
			  	<html:link action="/ViewSourceDetails" paramName="source" paramProperty="sourceId" paramId="source_id">
			  	Details
			  	</html:link>		  	
			  	<html:link action="/DeleteSource" paramName="source" paramProperty="sourceId" paramId="source_id">
			  	Delete
			  	</html:link>

			  	
			  </td>
		  </tr>
 	  </logic:iterate>
  </table>
  </logic:notEmpty>
  </logic:present>
  
  <logic:notPresent name="sources">
  <h3>There are no sources for this book</h3>
  </logic:notPresent>
			</div>
		</div>
	</div>
</div>


<div id="footer">
	<p id="copy">&copy;2007 LoneTree.</p>
	<p> (Andrew Lee | Bojan Martin | Dimeji Omikunle | Minghui Yu)</p>
</div>
  </body>
</html>
